package cn.kgc.biz.service;

import cn.kgc.biz.vo.HotelRoomVo;
import cn.kgc.dto.Dto;
import cn.kgc.mapper.HotelRoomMapper;
import cn.kgc.mapper.ImageMapper;
import cn.kgc.mapper.LabelDicMapper;
import cn.kgc.pojo.HotelRoom;
import cn.kgc.pojo.Image;
import cn.kgc.pojo.LabelDic;
import cn.kgc.util.DtoUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class HotelRoomServiceImpl implements HotelRoomService {
    @Resource
    private HotelRoomMapper hotelRoomMapper;
    @Resource
    private LabelDicMapper labelDicMapper;
    @Resource
    private ImageMapper imageMapper;
    @Override
    public Dto queryHotelRoomByHotel(HotelRoomVo hotelRoomVo) {
        HotelRoom hotelRoom=new HotelRoom();
        if (hotelRoomVo.getHotelId()!=null&& hotelRoomVo.getHotelId()!=0){
            hotelRoom.setHotelId(hotelRoomVo.getHotelId());
        }
        if (hotelRoomVo.getIsHavingBreakfast()!=null && hotelRoomVo.getIsHavingBreakfast()!=0){
            hotelRoom.setIsHavingBreakfast(hotelRoomVo.getIsHavingBreakfast());
        }
        if (hotelRoomVo.getIsBook()!=null&&hotelRoomVo.getIsBook()!=0){
            hotelRoom.setIsBook(hotelRoomVo.getIsBook());
        }
        if (hotelRoomVo.getRoomBedTypeId()!=null&& hotelRoomVo.getRoomBedTypeId()!=0){
            hotelRoom.setRoomBedTypeId(hotelRoomVo.getRoomBedTypeId());
        }
        if (hotelRoomVo.getPayType()!=null&&hotelRoomVo.getPayType()!=0){
           hotelRoom.setPayType(hotelRoomVo.getPayType());
        }
        if (hotelRoomVo.getIsTimelyResponse()!=null&& hotelRoomVo.getIsTimelyResponse()!=0){
            hotelRoom.setIsTimelyResponse(hotelRoomVo.getIsTimelyResponse());
        }
        if (hotelRoomVo.getIsCancel()!=null&&hotelRoomVo.getIsCancel()!=0){
            hotelRoom.setIsCancel(hotelRoomVo.getIsCancel());
        }
        List<HotelRoom> hotelRoomList=hotelRoomMapper.select(hotelRoom);
        List list=new ArrayList();
        for (HotelRoom hr:hotelRoomList){
            HotelRoom[] hotelRooms=new HotelRoom[]{hr};
            list.add(hotelRooms);
        }
        return DtoUtil.getSuccesWithData(list);
    }

    @Override
    public Dto queryHotelRoomBed() {
        List<LabelDic> labelDicList=labelDicMapper.getLabelDicByIds(2L,4L);
        return DtoUtil.getSuccesWithData(labelDicList);
    }

    @Override
    public Dto queryRoomImgByHotelId(Long hotelId) {
        Image image=new Image();
        image.setType("1");
        image.setTargetId(hotelId);
        List<Image> imageList=imageMapper.select(image);
        return DtoUtil.getSuccesWithData(imageList);
    }
}
